import axios from "axios"
let baseURL = process.env.VUE_APP_FETCHBASEURL
let isFullPathReg = /^http/


export default async (url, params, config = {}) => {
  url = isFullPathReg.test(url) ? url : baseURL + url
  let method = config.method || "post"
  let data = () => method === "get" ? { params } : { data: params } 
  let res = await axios({
    url,
    method,
    headers: config.headers || {
      "Content-Type": "application/json; charset=UTF-8"
    },
    ...data()
  })

  if (res.status === 200) {
    return res.data
  } else {
    return false
  }
}
